<?php
namespace Admin\Model;
use Think\Model;
class IndexModel extends Model {

    protected $tableName = "user";

    protected $_validate = array(
        array('login','require','登录名必须填写'),
        array('password','require','密码必须填写')
    );

    function getAccessUrls( $roleId){
        $rows =  $this->query('SELECT path FROM useable JOIN access ON useable.id = access.useable_id where role_id=%d',$roleId);
        $urls =array();
        foreach ($rows as $row){
            $urls[$row['path']] = true;
        }
        return $urls;
    }

    function Login()
    {
        $input = $this->create();
        if (empty($input)) {
            return;
        }

        $dbData = $this->getByLogin($input['login']);
        if (empty($dbData)) {
            $this->error = "用户不存在!";
            return;
        }

//        echo $zx;
//        echo $dbData['password'];
//        die;
        if ($dbData['password'] != $input['password']) {
            $this->error = "密码错误！!";
            return;
        }
        return $dbData;
    }
}